//
//  XiuGaiMiMaViewController.m
//  uplife
//
//  Created by ZhangCheng on 2018/12/27.
//  Copyright © 2018年 ZhangCheng. All rights reserved.
//

#import "XiuGaiMiMaViewController.h"

@interface XiuGaiMiMaViewController ()
@property(nonatomic,weak)IBOutlet UIView *tfSuperView1;
@property(nonatomic,weak)IBOutlet UIView *tfSuperView2;
@property(nonatomic,weak)IBOutlet UIView *tfSuperView3;

@property(nonatomic,weak)IBOutlet UITextField *oldPWDTF;
@property(nonatomic,weak)IBOutlet UITextField *PWDTF;
@property(nonatomic,weak)IBOutlet UITextField *confirmPWDTF;

@property(nonatomic,weak)IBOutlet UIView *confirmView;
@end

@implementation XiuGaiMiMaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.tfSuperView1.layer setBorderColor:[UIColor colorWithRed:203.0f/255.0f green:172.0f/255.0f blue:116.0f/255.0f alpha:1.0f].CGColor];
    [self.tfSuperView2.layer setBorderColor:[UIColor colorWithRed:203.0f/255.0f green:172.0f/255.0f blue:116.0f/255.0f alpha:1.0f].CGColor];
    [self.tfSuperView3.layer setBorderColor:[UIColor colorWithRed:203.0f/255.0f green:172.0f/255.0f blue:116.0f/255.0f alpha:1.0f].CGColor];
}

-(BOOL)canSendRequestForUpdatePWD{
    BOOL result = YES;
    NSString *code = [self.oldPWDTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *pwd = [self.PWDTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *pwd2 = [self.confirmPWDTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if (code.length==0) {
        [SVProgressHUD showErrorWithStatus:@"请输入旧密码"];
        result = NO;
        return result;

    }else if (pwd.length == 0){
        [SVProgressHUD showErrorWithStatus:@"请输入新密码"];
        result = NO;
        return result;

    }else if ([pwd isEqualToString:pwd2]==NO){
        [SVProgressHUD showErrorWithStatus:@"密码输入不一致"];
        result = NO;
        return result;

    }
    return result;
}

-(IBAction)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)submitAction{
    if ([self canSendRequestForUpdatePWD]) {
        NSString *code = [self.oldPWDTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        NSString *pwd = [self.PWDTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        NSString *urlString = [NSString stringWithFormat:@"%@/user/modifyPwd.do",JSXF_HOST];
        NSDictionary *params = @{
                                 @"oldPassword":code,
                                 @"newPassword":pwd
                                 };
        
        [SVProgressHUD show];
        
        [ZCWebServiceHelper requestWithMethod:POST andUrlStr:urlString andParameters:params andFinished:^(id response, NSURLSessionDataTask *dataTask) {
            [SVProgressHUD showSuccessWithStatus:response[@"message"]];
            self.confirmView.hidden = NO;
        }];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
